#include "headfiles.h"

using namespace std;

bool selectNum(int *array, int n, int m) {
    if (array == NULL ||
        n <= 0) {
        cout << "Invalid input argument!" << endl;
        return false;
    }

    int *array_copy = (int *)malloc(sizeof(int) * n);
    if (array_copy == NULL) {
        cout << "Allocate array copy buffer error!" << endl;
        return false;
    }
    memcpy(array_copy, array, sizeof(int) * n);

    int i, index;
    for (i = 0; i < m; i++) {
        index = rand() % (n - i) + i;
        int tmp = array_copy[i];
        array_copy[i] = array_copy[index];
        array_copy[index] = tmp;
    }

    for (i = 0; i < m; i++) {
        cout << array_copy[i] << endl;
    }

    free(array_copy);

    return true;
}

